﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace NFit.Core.Config.Xml
{
    /// <summary>
    /// A list of data sources
    /// </summary>
    [ConfigurationCollection(typeof(DatasourceElement), AddItemName = "source",
      CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class DatasourcesElementCollection : ConfigurationElementCollection
    {        
        /// <summary>
        /// Collection type
        /// </summary>
        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }

        /// <summary>
        /// Element name
        /// </summary>
        protected override string ElementName
        {
            get { return "source"; }
        }

        /// <summary>
        /// Creates a new child element
        /// </summary>
        /// <returns></returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new DatasourceElement();
        }

        /// <summary>
        /// Get element by key
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return (element as DatasourceElement).Name;
        }        
    }
}
